package com.toolbox.controller.infra;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.toolbox.annotation.OperateLog;
import com.toolbox.base.BaseController;
import com.toolbox.req.InfraUserRoleReq;
import com.toolbox.result.ResponseResultDTO;
import com.toolbox.service.InfraUserRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 用户角色表 前端控制器
 * </p>
 *
 * @author Mango
 * @since 2023-12-01
 */
@SuppressWarnings("ALL")
@ApiSort(100)
@Api(tags = "用户角色表 前端控制器")
@RestController
@RequestMapping("/user-role-do")
public class InfraUserRoleController extends BaseController {

    @Autowired
    private InfraUserRoleService service;



    /**
     * 创建——用户角色关系
     *
     * @param req 参数
     * @param bo  当前操作人
     * @return 主键ID
     */
    @OperateLog(operateName = "创建——用户角色关系", operateItem = "infra_user_role")
    @ApiOperationSupport(order = 100)
    @ApiOperation(value = "创建——用户角色关系")
    @PostMapping(value = "/create-user-role")
    public ResponseResultDTO<List<Long>> createUserRole(@RequestBody @Validated InfraUserRoleReq req) {
        return ResponseResultDTO.success(service.createUserRole(req, init()));
    }

    /**
     * 删除——用户角色关系
     *
     * @param id 主键ID
     */

    @OperateLog(operateName = "删除——用户角色关系", operateItem = "infra_user_role")
    @ApiOperationSupport(order = 100)
    @ApiOperation(value = "删除——用户角色关系")
    @ApiImplicitParam(name = "id", value = "主键ID", dataType = "Long", dataTypeClass = Long.class, paramType = "query", example = "1", required = true)
    @DeleteMapping(value = "/remove-by-id")
    public ResponseResultDTO<Void> removeById(@RequestParam(name = "id") Long id) {
        service.removeById(id);
        return ResponseResultDTO.success();
    }

}
